package com.jee6.umfrage;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;


/**
 *
 * @author Florian
 */
@Stateless
public class UserService {

    @PersistenceContext
    private EntityManager em;

    public void create(Userold user) {
       em.persist(user);
    }
 
  

    public void remove(User user) {
        em.remove(em.merge(user));
    }
   
 
 
//
//            public User addUserItem(User user, String description, String priority) {
//                user = em.merge(user);
//                UserItem item = new UserItem(description, priority);
//                user.add(item);
//                return user;
//            }
//
//            public User removeUserItem(User user, UserItem item) {
//                user = em.merge(user);
//                user.remove(item);
//                return user;
//            }
//
//    public User findByName(String name) throws NoSuchUserException {
//        List<User> resultList = em.createNamedQuery(User.FIND_BY_NAME, User.class)
//                .setParameter("name", name)
//                .getResultList();
//        if (resultList != null && resultList.size() > 1) {
//            throw new IllegalStateException("user named " + name + " was found more than once.");
//        }
//        if (resultList != null && resultList.size() == 1) {
//            return resultList.get(0);
//        }
//        throw new NoSuchUserException("user " + name + " doesn't exist.");
//    }

//    public List<User> findAll() {
//        return em.createNamedQuery(User.FIND_ALL, User.class).getResultList();
//    }

//    public long count() {
//        return ((Long) em.createQuery("select count(p) from User p").getSingleResult()).longValue();
//    }
//

    

   
    
}
